import dayjs from 'dayjs'
import { Button } from 'antd'
import { useState } from 'react'
import { useMount } from 'ahooks'

import { WijmoBase } from '../../Router/Wijmo'
import { GetIndexedDB } from '../../Utils/IndexedDB'
import { RedoOutlined, SearchOutlined, ExportOutlined, UserSwitchOutlined, FileMarkdownOutlined } from '@ant-design/icons';


const wijmoConfig = async () => {
    const options = await GetIndexedDB('options')
    return ({
        get: 'gettransportNotInFenceList',
        params: {
            statisticstype: 0,
            orgtype: 1,
            pageIndex: 1,
            pageSize: 10,
        },
        initParameter: {
            group: [],
            sort: [],
            groupPanel: true,
            filter: true,
            addSum: true,
            addIndex: true,
            topText: 'Ω',
            btmText: 'Ψ',
        },
        configuration: {
            allowSorting: 'MultiColumn',
            isReadOnly: true,
            selectionMode: 5,
            allowMerging: "Cells",
        },
        optionsBtn: click => ([
            {
                key: '0',
                type: 'group',
                label: '数据',
                children: [
                    { key: 'refresh', label: <Button type='link' onClick={() => click('onRefresh')} ><RedoOutlined style={{ color: '#13c2c2' }} />刷新数据</Button> },
                    { key: 'search', label: <Button type='link' onClick={() => click('onSearch')} ><SearchOutlined style={{ color: '#13c2c2' }} />条件搜索</Button> },
                ],
            },
            {
                key: '1',
                type: 'group',
                label: '审核',
                children: [
                    {
                        key: 'examine',
                        label: (
                            <Button
                                type='link'
                                onClick={() => click('onExamine', {
                                    type: 'WarningInfo',
                                    url: 'posTransportTransportRecords',
                                    pathArr: 'uuid'
                                })}
                            >
                                <UserSwitchOutlined style={{ color: '#13c2c2' }} />
                                审核数据
                            </Button>
                        )
                    },
                    { key: 'mapData', label: <Button type='link' onClick={() => click('onMap')} ><FileMarkdownOutlined style={{ color: '#13c2c2' }} />地图信息</Button> },
                ],
            },
            {
                key: '2',
                type: 'group',
                label: '导出',
                children: [
                    { key: '2-1', label: <Button type='link' onClick={() => click('onSaveAct')}><ExportOutlined style={{ color: '#13c2c2' }} />导出选中数据</Button> },
                    { key: '2-2', label: <Button type='link' onClick={() => click('onSaveAll')}><ExportOutlined style={{ color: '#13c2c2' }} />导出全部数据</Button> },
                ],
            },
        ]),

        columns: [
            {
                dataIndex: 'uuid',
                valueType: 'Hidden'
            },

            {
                title: '车牌号',
                dataIndex: 'yS_CheHao',
                valueType: 'Input',
                width: 120,
                align: 'center'
            },

            {
                title: '材料名称',
                dataIndex: 'yS_CaiLiaoName',
                valueType: 'Input',
                width: 160,
                align: 'center'
            },
            {
                title: '数量',
                dataIndex: 'yS_ShouLiaoShuLiang',
                valueType: 'Input',
                width: 160,
                align: 'center',
                hideInSearch: true,
            },
            {
                title: '单位',
                dataIndex: 'yS_Unit',
                valueType: 'Input',
                width: 100,
                align: 'center',
                hideInSearch: true,
            },
            {
                title: '运距(Km)',
                dataIndex: 'yS_YunShuJuLi',
                valueType: 'Input',
                width: 160,
                align: 'center',
                hideInSearch: true,
            },
            {
                title: '运费',
                dataIndex: 'yS_Money',
                valueType: 'Input',
                width: 160,
                align: 'center',
                format: 'n2',
                hideInSearch: true,
            },
            {
                title: '发料时间',
                dataIndex: 'yS_FaLiaoDate',
                valueType: 'Input',
                width: 200,
                align: 'center',
                hideInSearch: true,
            },
            {
                title: '发料地',
                dataIndex: 'yS_FaLiaoDi',
                width: 160,
                align: 'center',
                hideInSearch: true,
            },
            {
                title: '发料员',
                dataIndex: 'yS_FaLiaoYuan',
                width: 100,
                align: 'center',
                hideInSearch: true,
            },
            {
                title: '收料时间',
                dataIndex: 'yS_ShouLiaoDate',
                valueType: 'Input',
                width: 200,
                align: 'center',
                hideInSearch: true,
            },
            {
                title: '收料地',
                dataIndex: 'yS_ShouLiaoDi',
                width: 160,
                align: 'center',
                hideInSearch: true,
            },
            {
                title: '收料员',
                dataIndex: 'yS_ShouLiaoYuan',
                width: 100,
                align: 'center',
                hideInSearch: true,
            },
            {
                title: '承运单位',
                dataIndex: 'yS_YunShuFang',
                width: 240,
                align: 'center',
                hideInSearch: true,
            },
            {
                title: '审核状态',
                dataIndex: 'handled',
                valueType: 'Select',
                valueEnum: [{ value: 0, label: '未审核' }, { value: 1, label: '已审核' }],
                width: 100,
                align: 'center',
                hideInSearch: true,
            },
            {
                title: '审核意见',
                dataIndex: 'handleNote',
                width: 500,
                align: 'center',
                hideInSearch: true,
            },
        ],
    })
}

const WarningInfo = () => {
    const [WijmoConfig, setWijmoConfig] = useState()
    useMount(async () => setWijmoConfig(await wijmoConfig()))
    return (
        <div className='CaiLiaoFei'>
            {WijmoConfig && <WijmoBase Config={WijmoConfig} />}
        </div>
    )
};

export default WarningInfo;